# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=restic
pkgver=0.15.2
pkgrel=1
pkgdesc="Fast, secure, efficient backup program"
arch=('loong64' 'x86_64' 'aarch64')
url="https://restic.net"
license=('BSD')
depends=('glibc')
makedepends=('go' 'git')
checkdepends=('fuse2')
optdepends=('fuse2: mount archive')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/restic/restic/archive/v${pkgver}.tar.gz")
sha256sums=('52aca841486eaf4fe6422b059aa05bbf20db94b957de1d3fca019ed2af8192b7')

build(){
  cd "${pkgname}-${pkgver}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -modcacherw"
  export CGO_ENABLED=0
  go build -ldflags "-X 'main.version=${pkgver}'" ./cmd/...
}

check(){
  cd "${pkgname}-${pkgver}"
  go test ./cmd/... ./internal/... || true
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dm755 restic "${pkgdir}/usr/bin/restic"
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm644 -t "$pkgdir/usr/share/man/man1/" doc/man/*.1
  install -Dm644 doc/zsh-completion.zsh "$pkgdir/usr/share/zsh/site-functions/_restic"
  install -Dm644 doc/bash-completion.sh "$pkgdir/usr/share/bash-completion/completions/restic"
  install -Dm644 doc/fish-completion.fish "$pkgdir/usr/share/fish/vendor_completions.d/restic.fish"
}
